package com.belf.evaluatetool.web;

import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

@RestController
public class DownloadController {

    // 假设工程所在的根目录路径，这里需要根据实际情况修改
//    private static final String PROJECT_ROOT_PATH = "/path/to/your/project";

    @GetMapping("/download")
    public ResponseEntity<Resource> downloadProject() {
        String projectPath = System.getProperty("user.dir");
        File projectDir = new File(projectPath+"/evalTool.zip");
        System.out.println("projectPath: "+projectDir);
        Resource resource = new FileSystemResource(projectDir);

        HttpHeaders headers = new HttpHeaders();
        headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"evalTool.zip\"");
        headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_OCTET_STREAM_VALUE);

        return ResponseEntity.ok()
              .headers(headers)
              .body(resource);
    }
}